package com.qianclass.talklive.app.json.ImSendMessge;

import com.qianclass.talklive.app.bean.SpeakControlBean;
import com.qianclass.talklive.app.utils.Constant;
import com.qianclass.talklive.app.utils.LogUtil;
import com.qianclass.talklive.app.utils.ThreadUtils;
import com.google.gson.Gson;

import static com.qianclass.talklive.app.activity.VideoActivity.egine;


/**
 * 解、禁言
 * {
         "message":
         {
             "actoruserid":11881,
             "subcommand":"limittalk",
             "type":"member",
             "userid":11883         //useid=-1全体禁言
         }
    }
 */

public class SendSpeakControlMessage {

    /**
     * @param limit 是否禁言
     * @param userId
     * @param group
     */
    public static void sendMessge(boolean limit, int userId, int hostId, final String group) {
        try {
            SpeakControlBean speakControlBean = new SpeakControlBean();
            SpeakControlBean.MessageBean messageBean = new SpeakControlBean.MessageBean();
            messageBean.setType("member");
            messageBean.setActoruserid(hostId);
            messageBean.setUserid(userId);

            if (limit) {
                messageBean.setSubcommand("limittalk");
            }else {
                messageBean.setSubcommand("allowtalk");
            }

            speakControlBean.setMessage(messageBean);

            Gson gson = new Gson();
            final String jsonString = gson.toJson(speakControlBean);
            ThreadUtils.runOnSubThread(new Runnable() {
                @Override
                public void run() {
                    egine.SendGroupMessage(Constant.CONTROLMSGTYPE, group, jsonString);
                }
            });
            LogUtil.i("禁言" ,jsonString);
        } catch (Exception e){
            LogUtil.i("禁言" , "发送信息失败");
        }

    }
}
